﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>班级管理</title>
    <#include "../common/link.ftl">
    <script src="/js/plugins/messager/jquery.bootstrap.min.js"></script>
    <script>
        $(function () {
            $('.btn-delete').click(function () {
                //事件源查询到删除的id值
                var id = $(this).data('id');

                $.messager.confirm('警告', '是否要删除?', function () {
                    $.get('/classinfo/delete.do', {id: id}, handlerMessage)
                });
            })
        })
    </script>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <#include "../common/navbar.ftl">
    <!--菜单回显-->
    <#assign currentMenu="classinfo"/>
    <#include "../common/menu.ftl">
    <div class="content-wrapper">
        <section class="content-header">
            <h1>部门管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <!--高级查询--->
                <form class="form-inline" id="searchForm" action="/classinfo/list.do" method="post">
                    关键字:<input type="text" id="keyword" name="keyword" value="${qo.keyword!}">
                    班主任:
                    <select name="employee_id" id="empl">
                        <option value="-1">全部</option>
                            <#list employees as employee>
                                <option value="${employee.id}"  ${((qo.employee_id!-1) == employee.id) ?string("selected","")}>${employee.name}</option>
                            </#list>
                    </select>
                    <input type="submit" value="查询">
                    <input type="hidden" name="currentPage" id="currentPage" value="1">
                    <a href="#" class="btn btn-success btn-input" style="margin: 10px">
                        <span class="glyphicon glyphicon-plus"></span> 添加
                    </a>
                </form>
                <!--编写内容-->
                <div class="box-body table-responsive no-padding ">
                    <table class="table table-hover table-bordered">
                        <tr>
                            <th>编号</th>
                            <th>班级名称</th>
                            <th>班级人数</th>
                            <th>班主任</th>
                            <th>操作</th>
                        </tr>
                        <#list pageInfo.list as classinfo>
                            <tr>
                                <td>${classinfo_index+1}</td>
                                <td>${classinfo.name!}</td>
                                <td>${classinfo.number!}</td>
                                <td>${classinfo.employee_id!}</td>
                                <td>
                                    <a href="#" class="btn btn-info btn-xs btn-input" data-id='${classinfo.json!}'>
                                        <span class="glyphicon glyphicon-pencil"></span> 编辑
                                    </a>
                                    <a href="#" class="btn btn-danger btn-xs btn-delete" data-id='${classinfo.id!}'>
                                        <span class="glyphicon glyphicon-trash"></span> 删除
                                    </a>
                                </td>
                            </tr>
                        </#list>
                    </table>
                    <!--分页-->
                    <#include "../common/page.ftl">
                </div>
            </div>
        </section>
    </div>
    <#include "../common/footer.ftl">
</div>

<!-- Button trigger modal -->
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
    Launch demo modal
</button>

<!-- Modal -->
<div class="modal fade" id="deptModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <form class="form-horizontal" action="/classinfo/saveOrUpdate.do" method="post" id="editForm">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">新增或修改部门</h4>
                </div>
                <div class="modal-body">
                </div>
                <input type="hidden" name="id">
                <div class="form-group" style="margin-top: 10px;">
                    <label for="name" class="col-sm-3 control-label">班级名称：</label>
                    <div class="col-sm-6">
                        <input type="text" class="form-control" id="name" name="name"
                               placeholder="请输入班级名称">
                    </div>
                </div>
                <div class="form-group" style="margin-top: 10px;">
                    <label for="sn" class="col-sm-3 control-label">班级人数：</label>
                    <div class="col-sm-6">
                        <input type="text" class="form-control" id="number" name="number"
                               placeholder="请输入班级人数">
                    </div>
                </div>
                <div class="form-group" style="margin-top: 10px;">
                    <label for="sn" class="col-sm-3 control-label">班主任：</label>
                    <div class="col-sm-6">
                        <select name="employee_id" id="empl">
                            <option value="-1">全部</option>
                            <#list employees as employee>
                                <option value="${employee.id}"}>${employee.name}</option>
                            </#list>
                        </select>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary">保存</button>
                </div>
            </form>
        </div>
    </div>
    <script>
        $('.btn-input').click(function () {
            $('#deptModal').modal('show');
            $('#editForm input').val('');
            var data = $(this).data('id');
            if (data) {
                $('#editForm input[name="id"]').val(data.id);
                $('#name').val(data.name);
                $('#number').val(data.number);
                var $empl = $('#empl option');
                $empl.each(function (a,b) {
                    if ($(b).val() == data.employee_id) {
                        $(b).prop('selected',true);
                    }
                })
            }
        });

        $(function () {
            $('.btn-primary').click(function () {
                $('#editForm').ajaxSubmit(handlerMessage);
            })
        })

    </script>
</div>
</body>
</html>
